<include file="Public/min-header" />
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>

<div class="wrapper">
	<include file="Public/breadcrumb"/>
	<section class="content">
		<div class="row">
			<div class="col-xs-12">
				<div class="box">
					<div class="box-header">
						<nav class="navbar navbar-default">
							<div class="collapse navbar-collapse">
								<form class="navbar-form form-inline" action="{:U('Ad/adList')}/fenbu_id/{$fenbu_id}" method="get">
									<div class="form-group">
										<input type="text" name="keywords" class="form-control" value="{:I('keywords')}" placeholder="请输入广告名称">
									</div>
									<div class="form-group">
										<select name="pid" class="form-control">
											<option value="0">==查看所有==</option>
											<volist name="ad_position_list" id="item" key="k">
												<if condition="I('pid')==$item['position_id']">
													<option value="{$item.position_id}" selected="selected">{$item.position_name}</option>
													<else/>
													<option value="{$item.position_id}">{$item.position_name}</option>
												</if>
											</volist>
										</select>
									</div>
									<button type="submit" class="btn btn-primary">查询</button>
									<div class="form-group pull-right">
										<a href="{:U('Ad/ad')}/fenbu_id/{$fenbu_id}" class="btn btn-primary pull-right"><i class="fa fa-plus"></i> 新增{$fenbu_name}广告</a>
									</div>
								</form>
							</div>
						</nav>
					</div>
					<div class="box-body">
						<div class="row">
							<div class="col-sm-12">
								<table id="list-table" class="table table-bordered table-striped dataTable">
									<thead>
									<tr role="row">
										<th>广告id</th>
										<th>广告位置</th>
										<th>广告名称</th>
										<th>广告图片</th>
										<th>广告链接</th>
										<th>开始时间</th>
										<th>结束时间</th>
										<th>是否显示</th>
										<th>显示分部</th>
										<th>排序</th>
										<th>操作</th>
									</tr>
									</thead>
									<tbody>
									<foreach name="list" item="vo" key="k" >
										<tr role="row">
											<td>{$vo[ad_id]}</td>
											<td>{$ad_position_list[$vo[pid]][position_name]}</td>
											<td>{$vo.ad_name}</td>
											<td><img alt="" src="{$vo.ad_code}" width="80px" height="50px"></td>
											<td>
												<input type="text" onchange="updateSort('ad','ad_id','{$vo.ad_id}','ad_link',this)" value="{$vo.ad_link}" class="input-sm" style="width: 300px;text-align: center;">
											</td>
											<td>
												<input type="text" onchange="updateSortsss('ad','ad_id','{$vo.ad_id}','start_time',this)" value="{$vo.start_time}" class="start_time" style="width: 300px;text-align: center;">
											</td>
											<td>
												<input type="text" onchange="updateSortsss('ad','ad_id','{$vo.ad_id}','end_time',this)" value="{$vo.end_time}" class="end_time" style="width: 300px;text-align: center;">
											</td>

											<td>
												<img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[enabled] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('ad','ad_id','{$vo.ad_id}','enabled',this)"/>
											</td>
											<td>
												{$vo.fenbu_name}
											</td>
											<td>
												<input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onchange="updateSort('ad','ad_id','{$vo.ad_id}','orderby',this)" size="4" value="{$vo.orderby}" class="input-sm" />
											</td>
											<td>
												<a class="btn btn-primary" href="{:U('Ad/ad',array('act'=>'edit','ad_id'=>$vo['ad_id']))}/fenbu_id/{$fenbu_id}"><i class="fa fa-pencil"></i></a>
												<a class="btn btn-danger" onclick="delfunc(this)" data-url="{:U('Ad/adHandle')}" data-id="{$vo.ad_id}"><i class="fa fa-trash-o"></i></a>
											</td>
										</tr>
									</foreach>
									</tbody>
									<tfoot>

									</tfoot>
								</table>
							</div>
						</div>
						<div class="row">
							<div class="col-sm-6 text-left">
								<button class="btn btn-default btn-sm checkbox-toggle"><i class="fa fa-square-o"></i></button>
							</div>
							<div class="col-sm-6 text-right">{$page}</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
	<script>


		$(document).ready(function() {


			$('.start_time').daterangepicker({
				format:"YYYY-MM-DD HH:mm",
				singleDatePicker: true,
				showDropdowns: true,
				showWeekNumbers: true,
				timePicker: true,
				timePickerIncrement: 1,
				timePicker12Hour: false,
				opens: 'left',
				buttonClasses: ['btn btn-default'],
				applyClass: 'btn-small btn-primary',
				cancelClass: 'btn-small',
				locale : {
					applyLabel : '确定',
					cancelLabel : '取消',
					fromLabel : '起始时间',
					toLabel : '结束时间',
					customRangeLabel : '自定义',
					daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
					monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
					firstDay : 1
				}
			});

			$('.end_time').daterangepicker({
				format:"YYYY-MM-DD HH:mm",
				singleDatePicker: true,
				showDropdowns: true,
				showWeekNumbers: true,
				timePicker: true,
				timePickerIncrement: 1,
				timePicker12Hour: false,
				opens: 'left',
				buttonClasses: ['btn btn-default'],
				applyClass: 'btn-small btn-primary',
				cancelClass: 'btn-small',
				locale : {
					applyLabel : '确定',
					cancelLabel : '取消',
					fromLabel : '起始时间',
					toLabel : '结束时间',
					customRangeLabel : '自定义',
					daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
					monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
					firstDay : 1
				}
			});
		});
		var showtime = function (status) {
			var nowdate = new Date();
			var year = nowdate.getFullYear()
			var month = nowdate.getMonth() + 1
			if(status == 2){
				var date = nowdate.getDate()+1
			}else{
				var date = nowdate.getDate()
			}
			var h = nowdate.getHours(),
					m = nowdate.getMinutes(),
					s = nowdate.getSeconds();
			return year + "-" + month + "-" + date ;
		}
		//当前月最后一天
		function getLastDay(dateObj){
			var y = dateObj.getFullYear(); //获取年份
			var m = dateObj.getMonth() + 1; //获取月份
			var d = new Date(y, m, 0).getDate(); //获取当月最后一日
			m = m < 10 ? '0' + m : m; //月份补 0
			d = d < 10 ? '0' + d : d; //日数补 0
			return [y,m,d].join("-")
		}


		//当前月第一天
		function getFirstDay(dateObj){
			var y = dateObj.getFullYear(); //获取年份
			var m = dateObj.getMonth() + 1; //获取月份
			var d = '01';
			m = m < 10 ? '0' + m : m; //月份补 0
			return [y,m,d].join("-")
		}

		// shadow code修改指定表的排序字段
		function updateSortsss(table,id_name,id_value,field,obj)
		{
			var value = $(obj).val();
			$.ajax({
				url:"/index.php?m=Admin&c=Index&a=changeTableVals&table="+table+"&id_name="+id_name+"&id_value="+id_value+"&field="+field+'&value='+value,
				success: function(data){
					layer.msg('更新成功', {icon: 1});
					if(field == 'pda_offline'){
						location.reload();
					}
				}
			});
		}
	</script>
</div>
</body>
</html>   
